﻿
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_SMS_UpdateHistoryRecord]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_SMS_UpdateHistoryRecord];
GO
CREATE PROCEDURE [dbo].[sproc_SMS_UpdateHistoryRecord]
    @MsgIDS           nvarchar(4000),
    @RstCodeS         nvarchar(4000)
               
/*

============================================================
功能:    更新历史记录中记录的发送结果值
参数:
    @MsgIDS                nvarchar(5000)    :    消息ID字符串，用逗号相隔
    @RstCodeS         nvarchar(5000)    :    消息返回值字符串，用逗号相隔
    
注意:    @MsgIDS与@RstCodeS必须一一对应
============================================================

*/

AS
BEGIN

SET NOCOUNT ON
DECLARE @MsgID nvarchar(300)
DECLARE @RtnCode nvarchar(300)

WHILE LEN(@MsgIDS)>0 
BEGIN
    --如果不是最后一次
IF(charindex(',',@MsgIDS)>0)
BEGIN
    --截取逗号前数据
    SET @MsgID = substring(@MsgIDS,1,charindex(',',@MsgIDS)-1)
    SET @RtnCode = substring(@RstCodeS,1,charindex(',',@RstCodeS)-1)
    
    --剪切字符串
    SET @MsgIDS = substring(@MsgIDS,charindex(',',@MsgIDS)+1,LEN(@MsgIDS))    
    SET @RstCodeS = substring(@RstCodeS,charindex(',',@RstCodeS)+1,LEN(@RstCodeS))    

    UPDATE UDS_SMS_MobileMsgSendHistory SET ResultCode = @RtnCode WHERE MsgID=@MsgID 
END 
ELSE
BEGIN        
    UPDATE UDS_SMS_MobileMsgSendHistory SET ResultCode = @RstCodeS WHERE MsgID=@MsgIDS;
    BREAK
END

END

END
GO